package com.vue;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JPanel;

import com.controleur.listener.impl.CarteControler;
import com.modele.entity.Consomptible;
import com.modele.entity.Menu;

public class CarteApercuVue  extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel titreLabel,menuLabel,carteLabel,nom,prix,detailMenu;

	private List<Menu> listMenu;
	private List<Consomptible> listConsomptible;

	Fenetre fenetre;

    public CarteApercuVue(Fenetre f,int idCarte) {
    	CarteControler controler = new CarteControler();
    
    	this.fenetre = f;
    	this.listMenu=controler.findAllMenuByCarte(idCarte);
    	this.listConsomptible=controler.findAllConsomptibleByCarte(idCarte);
    	this.initialize();
		this.build();
    }
	public void initialize() {
	
        /* 1- Initialisation du container. */
        this.setLayout(new GridBagLayout());
        titreLabel = new JLabel("Carte :");
        menuLabel = new JLabel("Les Menu");
        carteLabel = new JLabel("A la carte");
 	}
	public void build(){
		 /*3- Ajout de ces composants en spécifiant les contraintes de type GridBagConstraints. */
        GridBagConstraints gbc = new GridBagConstraints();
        
        //titre de la page
        Font titreFont = new Font("Serif", Font.PLAIN, 26);
        titreLabel.setFont(titreFont);
        gbc.gridx = gbc.gridy = 0; 
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridheight = 1;
        gbc.anchor = GridBagConstraints.CENTER; 
        gbc.insets = new Insets(15, 0, 15, 0); 
        this.add(titreLabel, gbc);
       
        //consomptible
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.weightx = 0;
        gbc.insets = new Insets(10, 0, 0, 10);
        this.add(carteLabel, gbc);

        int placementY=2;
        for(int i=0;i<listConsomptible.size();i++){
        	nom = new JLabel(listConsomptible.get(i).getNom());
        	prix = new JLabel(String.valueOf(listConsomptible.get(i).getPrix()));
        	System.out.println("nom "+nom);
            gbc.gridx = 0;
            gbc.gridy = placementY++;
            gbc.gridheight = gbc.gridwidth = 1;
            gbc.anchor = GridBagConstraints.BASELINE_LEADING;
            gbc.insets = new Insets(0, 10, 0, 0);
            this.add(nom, gbc);

            //nom textField
            gbc.gridx = 1;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.anchor = GridBagConstraints.BASELINE_LEADING;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.insets = new Insets(5, 10, 0, 10);
            this.add(prix, gbc);
        }

        //menu
        gbc.gridx = 0;
        gbc.gridy = placementY+=1;
        gbc.weightx = 0;
        gbc.insets = new Insets(10, 0, 0, 10);
        this.add(menuLabel, gbc);
        List<Consomptible> listeConsomptible;
        placementY+=2;
        String composantMenu="";
        for(int i=0;i<listMenu.size();i++){
        	
        	nom = new JLabel(listMenu.get(i).getNomMenu());
        	prix = new JLabel(String.valueOf(listMenu.get(i).getPrix()));
        	
        	listeConsomptible=listMenu.get(i).getListConsomptibles();
        	
            gbc.gridx = 0;
            gbc.gridy = placementY++;
            gbc.gridheight = gbc.gridwidth = 1;
            gbc.anchor = GridBagConstraints.BASELINE_LEADING;
            gbc.insets = new Insets(0, 10, 0, 0);
            this.add(nom, gbc);
        	
            for(int j=0;j<listeConsomptible.size();j++){
            	composantMenu+=listeConsomptible.get(j).getNom()+", ";
        	}
            detailMenu = new JLabel(composantMenu);
            //consomptible
            gbc.gridx = 1;
            gbc.insets = new Insets(5, 10, 0, 10);
            this.add(detailMenu, gbc); 	
            //prix
            gbc.gridx = 2;
            this.add(prix, gbc);
        }
        this.setMinimumSize(new Dimension(500, 325));

	}

}
